package com.etc.zmall.service.impl;

import java.util.List;

import com.etc.dao.impl.GoodsDaoImpl;
import com.etc.dao.impl.ShopCartDaoImpl;
import com.etc.entity.Goods;
import com.etc.entity.Shopc;
import com.etc.util.PageData;
import com.etc.zmall.service.GoodsService;

/**
 * 
 * <p>
 * Title: GoodsServiceImpl
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * @author knowno
 * 
 * @date 2021年1月11日
 * 
 */
public class GoodsServiceImpl implements GoodsService {
	GoodsDaoImpl gd = new GoodsDaoImpl();
	ShopCartDaoImpl sc = new ShopCartDaoImpl();

	/**
	 * 分页查询全部商品
	 */
	@Override
	public PageData<Goods> showGoods(int page, int pageSize, String keywords) {
		if (page < 1) {
			page = 1;
		} else if (page > pageSize) {
			page = pageSize;
		}
		PageData<Goods> pd = gd.queryGoods(page, pageSize, keywords);
		return pd;
	}

	/**
	 * 添加商品进入购物车
	 */
	@Override
	public boolean addShopc(Shopc shopc) {

		boolean flag = sc.addShopCar(shopc);
		if (flag)
			// 添加成功
			return true;
		return false;
	}

	@Override
	public Goods selShopName(Goods goods, String goodsname) {
		return sc.selShopName(goods, goodsname);
	}

	@Override
	public PageData<Goods> queryGoodsShopid(int page, int pageSize, int shopid) {
		if (page < 1) {
			page = 1;
		} else if (page > pageSize) {
			page = pageSize;
		}
		return gd.queryGoodsShopid(page, pageSize, shopid);
	}

	@Override
	public boolean setGoodsState(int id, int state) {
		boolean f = gd.updateGoods(id, state);
		return f;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * <p>
	 * Title: addGoods
	 * </p>
	 * 
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @param goods
	 * @return
	 * 
	 * @see com.etc.zmall.service.GoodsService#addGoods(com.etc.zmall.entity.Goods)
	 * 
	 */
	@Override
	public boolean addGoods(Goods goods) {
		// TODO Auto-generated method stub
		return gd.addGoods(goods);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * <p>
	 * Title: queryOneGoods
	 * </p>
	 * 
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @param goodsid
	 * @return
	 * 
	 * @see com.etc.zmall.service.GoodsService#queryOneGoods(int)
	 * 
	 */
	@Override
	public Goods queryOneGoods(int goodsid) {
		// TODO Auto-generated method stub
		return gd.queryOneGoods(goodsid);
	}

}
